package ui;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import download.Download;

public class FinishedModel extends AbstractTableModel
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 608554331468966021L;

	private String[] cols;
	private ArrayList<Download> downloads = new ArrayList<Download>();
	
	public FinishedModel(String[] cols)
	{
		this.cols = cols;
	}
	@Override
	public int getColumnCount()
	{
		return cols.length;
	}

	public void addDownload(Download dl)
	{
		downloads.add(dl);
	}
	
	public void remove(int row)
	{
		downloads.remove(row);
	}
	
	public void remove(Download dl)
	{
		downloads.remove(dl);
	}
	@Override
	public int getRowCount()
	{
		return downloads.size();
	}

	@Override 
	public String getColumnName(int col)
	{
		return cols[col];
	}
	public Download getRowAt(int row)
	{
		return downloads.get(row);
	}
	@Override
	public Object getValueAt(int row, int col)
	{
		Download dl = downloads.get(row);
		if(col == 0)
			return dl.getUrl();
		if(col == 1)
			return dl.getPath();
		if(col == 2)
			return dl.getStringType();
		return null;
	}

}
